package com.link.base.base.product.controller;


import com.link.base.base.product.model.GuideProdCase;
import com.link.base.base.product.service.GuideProdCaseService;
import com.link.core.basic.controller.BasicController;
import com.link.core.basic.service.BasicService;
import com.link.core.cllog.LCLogger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 *
 * @author unknown
 * @date unknown
 * @comments 案例与产品操作
 */
@Controller
@RequestMapping("/link/GuideProdCase")
public class GuideProdCaseController extends BasicController<GuideProdCase> {

    @Resource
    private GuideProdCaseService guideProdCaseService;

    @Override
    public BasicService<GuideProdCase> getBasicService() throws Exception {
        return guideProdCaseService;
    }

    /**
     * 根据案例id查询与之相关联的产品集合
     */
    @RequestMapping(value = "/queryByCaseBaseId")
    @ResponseBody
    public Map<String, Object> queryByCaseBaseId(GuideProdCase entity, HttpSession session, HttpServletRequest request,
                                                 HttpServletResponse response) {
        Map<String, Object> result = new HashMap<String, Object>();
        try {
            List<GuideProdCase> list = guideProdCaseService.queryByCaseBaseId(entity);
            result.put("success", true);
            result.put("result", list);
            result.put("count", list.size());
        } catch (Exception e) {
            LCLogger.withException(e);
            result.put("success", false);
            result.put("result", new ArrayList<GuideProdCase>());
            result.put("message", e.getMessage());
        }
        return result;
    }

    /**
     * 根据案例id查询与之相关联的产品集合
     */
    @RequestMapping(value = "/queryByProductId")
    @ResponseBody
    public Map<String, Object> queryByProductId(GuideProdCase entity, HttpSession session, HttpServletRequest request,
                                                HttpServletResponse response) {
        Map<String, Object> result = new HashMap<String, Object>();
        try {
            List<GuideProdCase> list = guideProdCaseService.queryByProductId(entity);
            result.put("success", true);
            result.put("result", list);
            result.put("count", list.size());
        } catch (Exception e) {
            LCLogger.withException(e);
            result.put("success", false);
            result.put("result", new ArrayList<GuideProdCase>());
            result.put("message", e.getMessage());
        }
        return result;
    }
}
